"""搜索记录相关接口"""

from fastapi import APIRouter, Depends, Request
from sqlalchemy.ext.asyncio import AsyncSession

from config.get_db import get_db
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.entity.vo.search_record_vo import SearchRecordQueryModel
from module_admin.service.search_record_service import SearchRecordService
from utils.log_util import logger
from utils.page_util import PageResponseModel
from utils.response_util import ResponseUtil

searchRecordController = APIRouter(prefix='/agent/search-record', tags=['搜索记录管理'])


@searchRecordController.get(
    '/list',
    response_model=PageResponseModel,
    dependencies=[Depends(CheckUserInterfaceAuth('agent:searchRecord:list'))]
)
async def get_search_record_list(
    request: Request,
    search_query: SearchRecordQueryModel = Depends(SearchRecordQueryModel),
    page_num: int = 1,
    page_size: int = 10,
    db: AsyncSession = Depends(get_db)
):
    """获取搜索记录列表"""

    try:
        result = await SearchRecordService.get_record_list(
            db=db,
            query_params=search_query,
            page_num=page_num,
            page_size=page_size
        )
        return ResponseUtil.success(data=result)
    except Exception as exc:
        logger.exception(exc)
        return ResponseUtil.error(msg=str(exc))
